import {
    msg,confirm
} from '../common/layer';

const removeBtnHandler = () => {
    let selectedList = $('#table').bootstrapTable('getSelections');
    if (selectedList.length === 0) {
        msg('请至少选择一项');
        return;
    }
    let removeidAry = [];
    $.each(selectedList, (key, val) => {
        let removeid = val.id;
        removeidAry.push(removeid);
    });

    let removeidStr = removeidAry.join(',');

    confirm(`确定删除这 ${removeidAry.length} 条记录？`, '删除', function () {

        $.post(GLOBAL_proRemoveUrl, {
            id: removeidStr
        }, function (res) {
            if (res.rel == 1) {
                msg(res.msg, () => {
                    layer.closeAll();
                    let options=$('#table').bootstrapTable('getOptions');
                    $('#table').bootstrapTable('destroy');
                    $('#table').bootstrapTable(options);
                });
            } else {
                msg(res.msg);
            }
        }, 'json');
    });


}

export {
    removeBtnHandler
}